﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace GA.Server.ApiInfo
{
    [Serializable]
    public class ApiPlayer
    {
        public int AccountId { get; private set; }
        public int AgencyId { get; private set; }
        public string AgencyName { get; private set; }
        public int AllianceId { get; private set; }
        public string AllianceName { get; private set; }
        public DateTime FirstPlayed { get; private set; }
        public DateTime LastPlayed { get; private set; }
        public int PlayerId { get; private set; }
        public string PlayerName { get; private set; }
        public string PlayerRank { get; private set; }
        public int Missions { get; private set; }
        public IEnumerable<ApiCharacter> Characters { get; private set; }
        public string WinPercentage { get; private set; }

        public ApiPlayer()
        {
        }

        public ApiPlayer(XmlReader reader)
        {
            while (!reader.EOF)
            {
                reader.Read();
                if (reader.NodeType == XmlNodeType.Element)
                {
                    switch (reader.Name)
                    {
                        case "a:account_id": AccountId = int.Parse(ApiXmlNode.GetValue(reader)); break;
                        case "a:agency_id": AgencyId = int.Parse(ApiXmlNode.GetValue(reader)); break;
                        case "a:agency_name": AgencyName = ApiXmlNode.GetValue(reader); break;
                        case "a:alliance_id": AllianceId = int.Parse(ApiXmlNode.GetValue(reader)); break;
                        case "a:alliance_na": AllianceName = ApiXmlNode.GetValue(reader); break;
                        case "a:firstplayed": FirstPlayed = DateTime.Parse(ApiXmlNode.GetValue(reader)); break;
                        case "a:lastplayed": LastPlayed = DateTime.Parse(ApiXmlNode.GetValue(reader)); break;
                        case "a:player_id": PlayerId = int.Parse(ApiXmlNode.GetValue(reader)); break;
                        case "a:player_na": PlayerName = ApiXmlNode.GetValue(reader); break;
                        case "a:rank": PlayerRank = ApiXmlNode.GetValue(reader); break;
                        case "a:missions": Missions = int.Parse(ApiXmlNode.GetValue(reader)); break;
                        case "a:WinPercentage": WinPercentage = ApiXmlNode.GetValue(reader); break;
                    }
                }
            }
        }
    }
}
